package net.siufung.market.base.dept.controller.regulation;

import lombok.AllArgsConstructor;
import net.siufung.core.exception.BizServiceException;
import net.siufung.core.model.VerifyRepeatDto;
import net.siufung.core.model.enums.MethodEventEnum;
import net.siufung.core.model.regulation.AbstractRegulation;
import net.siufung.market.base.dept.controller.model.dto.DeptUpdateDto;
import net.siufung.market.base.dept.mapper.IDeptMapper;

/**
 * @author 陈建峰
 * @since 2022/7/31 10:48 下午
 */
@AllArgsConstructor
public class DeptUpdateRegulation extends AbstractRegulation<DeptUpdateDto> {

    private static final long serialVersionUID = 4821352829614836190L;

    private final IDeptMapper deptMapper;

    @Override
    public boolean isSatisfiedBy(DeptUpdateDto deptUpdateDto) {
        VerifyRepeatDto<String> verifyRepeatDto = new VerifyRepeatDto<>();
        verifyRepeatDto.setMethodEventEnum(MethodEventEnum.UPDATE);
        verifyRepeatDto.setPk(deptUpdateDto.getId());
        verifyRepeatDto.setVerifyKeyValue(deptUpdateDto.getDeptName());
        if(!deptMapper.checkDeptNameNotRepeat(verifyRepeatDto)){
            throw new BizServiceException("部门名称重复！");
        }
        return Boolean.TRUE;
    }
}
